{extend name="layout/main"}
{block name='title'}评价管理{/block}

{block name='main'}
<div class="container-fluid cm-container-white">
    <h3 style="margin:0">评价管理
        <div class="nav nabbar-nav" role="navigation">
            <div>
                <form action="{:url('admin/evaluation/index')}" method="get" class="navbar-form navbar-right">
                    <div class="form-group">
                        <label class="small">用户:</label>
                        <input type="text" value="{$uid}" class="form-control" name="uid" placeholder="请输入用户id"/>
                    </div>
                    <div class="form-group">
                        <label class="small">出版物:</label>
                        <input type="text" value="{$pid}" class="form-control" name="pid" placeholder="请输入出版物id"/>
                    </div>
                    <button type="submit" class="btn btn-default">提交</button>
                </form>
            </div>
        </div>
    </h3>
    <div class="table-responsive">
        <table class="table table-hover">
            <thead class="row">
            <tr>
                <th class="col-sm-1">id</th>
                <th class="col-sm-1">用户</th>
                <th class="col-sm-1">出版物</th>
                <th class="col-sm-1">星级评价</th>
                <th class="col-sm-5">评价内容</th>
                <th class="col-sm-1">评价时间</th>
                <th class="col-sm-2">操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $data as $item}
            <tr>
                <td>{$item.id}</td>
                <td>
                    <a href="{:url('admin/user/index', ['name' => $item.username])}">
                        {$item.username}
                    </a>
                </td>
                <td>
                    <a href="{:url('admin/index/showpublication', ['pid' => $item.p_id])}">
                        {$item.pname}
                    </a>
                </td>
                <td class="text-center">{$item.star}</td>
                <td>{$item.content}</td>
                <td>{$item.etime}</td>
                <td data-id="{$item.id}" data-star="{$item.star}" data-content="{$item.content}">
                    <button class="btn btn-primary saveEval" type="button">修改</button>
                    <button class="btn btn-danger delEval" type="button">删除</button>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
    <div class="text-center">
        {$data->render()}
    </div>
</div>

<div class="modal fade" id="evalModal" tabindex="-1" role="dialog" aria-labelledby="evalModalLabel" aria-hidden="true">
    <form action="{:url('admin/evaluation/save')}" method="post" class="form-horizontal">
        <input id="id" type="hidden" name="id" value="">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">
                        修改
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">五星评分</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="star" name="star">
                                <option value="5">5</option>
                                <option value="4">4</option>
                                <option value="3">3</option>
                                <option value="2">2</option>
                                <option value="1">1</option>
                            </select>
                            <span class="help-block">最少选择一颗星。</span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="content" class="col-sm-2 control-label">文本框</label>
                        <div class="col-sm-10">
                            <textarea id="content" name="content" class="form-control" rows="5" placeholder="请输入评价内容"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </form>
</div>

<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <form action="{:url('admin/evaluation/del')}" method="post">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">删除</h4>
            </div>
            <div class="modal-body">确认删除?</div>
            <input id="eval_id" type="hidden" name="eid" value="">
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" class="btn btn-primary">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
    </form>
</div>

{/block}

{block name='js'}
<script>
    $(function () {
        $('#cm-menu-scroller > ul > li:nth-child(6)').addClass('active');

        $("[data-toggle='tooltip']").tooltip();
    });

    $('.saveEval').click(function () {
        id = $(this).parent().data('id');
        star = $(this).parent().data('star');
        content = $(this).parent().data('content');

        $('#id').val(id)
        $('#star').val(star);
        $('#content').val(content)

        $("#evalModal").modal();

    });

    $('.delEval').click(function () {
        id = $(this).parent().data('id');

        $('#eval_id').val(id);
        $("#delModal").modal();
    });

</script>
{/block}